package com.sky.controller.user;

import com.sky.entity.Category;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.CommonService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class CommonController {
    @Autowired
    private CommonService commonService;

    /**
     * 总页面浏览
     * @param type
     * @return
     */
    @GetMapping("/user/category/list")
    public Result<List<Category>> categoryList(Integer type){
        List<Category> category = commonService.categoryList(type);
        return Result.success(category);
    }

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/user/setmeal/list")
    public Result <List<Setmeal>> setmealList(Integer categoryId){
        List<Setmeal> setmealList = commonService.setmealList(categoryId);
        System.out.println(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐id查询包含的菜品
     * @param id
     * @return
     */
    @GetMapping("/user/setmeal/dish/{id}")
    public Result<List<DishItemVO>> setmealDishList(@PathVariable Long id){
        List<DishItemVO> dishItemVO = commonService.setmealDishList(id);
        return Result.success(dishItemVO);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/user/dish/list")
    public Result<List<DishVO>> dishList(Long categoryId){
        List<DishVO> dishVO = commonService.dishList(categoryId);
        return Result.success(dishVO);
    }
}
